using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Web;
using System.IO;

namespace Pixysoft.Web
{
    public class WebHelper
    {
        private static WebHelper instance;
        public static WebHelper Instance
        {
            get
            {
                lock (typeof(WebHelper))
                {
                    if (instance == null)
                        instance = new WebHelper();
                    return instance;
                }
            }
        }

        private const int INTERNET_CONNECTION_MODEM = 1;
        private const int INTERNET_CONNECTION_LAN = 2;

        /// <summary>
        /// http://bbs.bccn.net/thread-239599-1-1.html
        /// </summary>
        /// <param name="dwFlag"></param>
        /// <param name="dwReserved"></param>
        /// <returns></returns>
        [DllImport("winInet.dll")]
        private static extern bool InternetGetConnectedState(
        ref   int dwFlag,
        int dwReserved
        );

        public bool IsConnectedToInternet()
        {
            int Desc = 0;

            try
            {
                return InternetGetConnectedState(ref Desc, 0);
            }
            catch
            {
                return false;
            }
        }

    }
}
